<template>
  <el-form inline ref="form">
    <el-form-item style="width: 250px" label="一级分类">
      <el-select
        :disabled="scene === 1"
        v-model="categoryStore.categoryIdObj.category1Id"
        @change="handler"
      >
        <el-option
          v-for="c1 in categoryStore.c1Arr"
          :key="c1.id"
          :label="c1.name"
          :value="c1.id"
        ></el-option>
      </el-select>
    </el-form-item>
    <el-form-item label="二级分类">
      <el-select
        :disabled="scene === 1"
        v-model="categoryStore.categoryIdObj.category2Id"
        @change="handler1"
      >
        <el-option
          v-for="c2 in categoryStore.c2Arr"
          :key="c2.id"
          :label="c2.name"
          :value="c2.id"
        ></el-option>
      </el-select>
    </el-form-item>
    <el-form-item label="三级分类">
      <el-select
        :disabled="scene === 1"
        v-model="categoryStore.categoryIdObj.category3Id"
      >
        <el-option
          v-for="c3 in categoryStore.c3Arr"
          :key="c3.id"
          :label="c3.name"
          :value="c3.id"
        ></el-option>
      </el-select>
    </el-form-item>
  </el-form>
</template>

<script lang="ts" setup>
import { onMounted } from 'vue'
import useCategoryStore from '@/store/modules/category'

defineProps(['scene'])
let categoryStore = useCategoryStore()
onMounted(() => {
  getCategory1()
})

async function getCategory1() {
  categoryStore.getC1()
}

function handler() {
  categoryStore.categoryIdObj.category2Id = ''
  categoryStore.categoryIdObj.category3Id = ''
  categoryStore.c3Arr = []
  categoryStore.getC2()
}

function handler1() {
  categoryStore.categoryIdObj.category3Id = ''
  categoryStore.getC3()
}
</script>

<style scoped lang="scss">
:deep(.el-form-item) {
  width: 250px;
}
</style>
